﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Path.Question;

namespace Path.Answer
{
    class Sofia:IPath
    {

        public string GetRelativePath(string currentPath, string targetPath)
        {           
            char[] cutChar = "/".ToCharArray();
            string[] curlist = currentPath.Split(cutChar);
            string[] tarlist = targetPath.Split(cutChar);

            string temp = "";

            if(curlist.Length==tarlist.Length)
            {
                for (int i = 1; i < curlist.Length; )
                {
                    if (curlist[i] == tarlist[i]) i++;
                    else 
                    {
                        for (int j = i; curlist[i]!=""&&j < curlist.Length; j++)
                            temp = temp + "../";
                        for (int j = i; tarlist[i] != "" && j < tarlist.Length; j++)
                            temp = temp + tarlist[j] + "/";
                        break;
                    }
                }
            }
            else if (curlist.Length < tarlist.Length)
            {
                for (int i = 1; i < curlist.Length; )
                {
                    if (curlist[i] == tarlist[i])
                    {
                        i++;
                        if (i == curlist.Length)
                        {
                            for (int j = i; j < tarlist.Length; j++)
                                temp = temp + tarlist[j] + "/";
                            break;
                        }
                    }
                    else
                    {
                        for (int j = i; curlist[i]!=""&&j < curlist.Length; j++)
                            temp = temp + "../";
                        for (int j = i; j < tarlist.Length; j++)
                            temp = temp + tarlist[j] + "/";
                        break;
                    }
                }

            }
            else if (curlist.Length > tarlist.Length)
            {
                for (int i = 1; i < tarlist.Length; )
                {
                    if (curlist[i] == tarlist[i])
                    {
                        i++;
                        if (i == tarlist.Length)
                        {
                            for (int j = i; j < curlist.Length; j++)
                                temp = temp + "../";
                            break;
                        }
                    }
                    else
                    {
                        for (int j = i; j < curlist.Length; j++)
                            temp = temp + "../";
                        for (int j = i; tarlist[i]!=""&&j < tarlist.Length; j++)
                            temp = temp + tarlist[j] + "/";
                        break;
                    }
                }
            }

            string result = temp.Substring(0, temp.Length - 1);
            return result;

        }
    }
}
